﻿using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.Package.Automation;
using VsCommands = Microsoft.VisualStudio.VSConstants.VSStd97CmdID;
using VsCommands2K = Microsoft.VisualStudio.VSConstants.VSStd2KCmdID;
using Microsoft.VisualStudio;
using System;

namespace Microsoft.StoryboardDesigner.Platform.CustomProjects
{
    public class StoryboardDesignerProjectFileNode : FileNode
    {
        #region Fields
        private OAStoryboardDesignerProjectFileItem automationObject;
        #endregion

        #region Constructors
        internal StoryboardDesignerProjectFileNode(ProjectNode root, ProjectElement e)
            : base(root, e)
        {
        }
        #endregion

        #region Overriden implementation
        public override int ImageIndex
        {
            get
            {
                return StoryboardDesignerProjectNode.imageOffset + (int)StoryboardProjectImageName.File;
            }
        }

        protected override NodeProperties CreatePropertiesObject()
        {
            return new StoryboardDesignerProjectFileNodeProperties(this);
        }

        public override object GetAutomationObject()
        {
            if(automationObject == null)
            {
                automationObject = new OAStoryboardDesignerProjectFileItem(this.ProjectMgr.GetAutomationObject() as OAProject, this);
            }

            return automationObject;
        }

        internal OleServiceProvider.ServiceCreatorCallback ServiceCreator
        {
            get { return new OleServiceProvider.ServiceCreatorCallback(this.CreateServices); }
        }

        private object CreateServices(Type serviceType)
        {
            object service = null;
            if(typeof(EnvDTE.ProjectItem) == serviceType)
            {
                service = GetAutomationObject();
            }
            return service;
        }
        #endregion
    }
}
